package com.orangelife.mobile.pay.biz;

import com.common.sp.UserSp;
import com.curry.android.http.VolleyHttpUtil;
import com.curry.android.util.StringUtil;
import com.curry.android.util.ToastHelper;
import com.orangelife.arenasdk.util.MD5Util;
import com.orangelife.mobile.constants.PayURL;

import java.util.HashMap;


/**
 * 支付密码的服务端接口
 * <p>
 * <p>
 * Created by 吴格非 on 2017-1-4.
 * <p>
 *
 * @author 吴格非
 * @since v1.0.0
 */

public class PayPwdHttpBiz {

    /** 校验密码 */
    public static void validatePayPwd(String pwd, VolleyHttpUtil.ResponseCallBack callback) {
        payPwd(PayURL.PAY_PWD_VALIDATE, pwd, callback);
    }

    /** 设置支付密码 */
    public static void commitPayPwd(String pwd, VolleyHttpUtil.ResponseCallBack callback) {
        payPwd(PayURL.PAY_PWD_SET, pwd, callback);
    }

    private static void payPwd(String url, String pwd, VolleyHttpUtil.ResponseCallBack callback) {
        if (StringUtil.isBlank(pwd)) {
            ToastHelper.getInstance()._toast("密码为空,请重试");
            return;
        }
        HashMap<String, Object> map = new HashMap<>();
        String newPayPwd = MD5Util.getMessageDigest((UserSp.getLoginID() + String.valueOf(pwd)).getBytes());
        map.put("paymentPwd", newPayPwd);
        VolleyHttpUtil.getInstance().postWithCallback(url, map, callback);
    }

    /** 获取支付密码信息 */
    public static void getPayPwdInfo(VolleyHttpUtil.ResponseCallBack callback) {
        VolleyHttpUtil.getInstance().getWithCallback(PayURL.PAY_PWD_INFO, callback);
    }

    /** 设置支付密码 */
    public static void modPayPwd(String pwd, String verifyCode, VolleyHttpUtil.ResponseCallBack callback) {
        if (StringUtil.isBlank(pwd)) {
            ToastHelper.getInstance()._toast("密码为空,请重试");
            return;
        }
        HashMap<String, Object> map = new HashMap<>();
        String newPayPwd = MD5Util.getMessageDigest((UserSp.getLoginID() + String.valueOf(pwd)).getBytes());
        map.put("paymentPwd", newPayPwd);
        map.put("verifyCode", verifyCode);
        VolleyHttpUtil.getInstance().putWithCallback(PayURL.PAY_PWD_MOD, map, callback);
    }
}
